local function BuyXCommands(ply, txt, toteam, isdead)
    for ent, tbl in pairs(scripted_ents.GetSpawnable()) do
        if tbl.Base == "base_structure" then
		AddChatCommand("/buy"..string.Replace(tbl.Classname,"struct_",""), BuyXSents, tbl.Classname)
		end
    end
end
hook.Add("InitPostEntity", "buyxcommands", BuyXCommands)

function BuyXSents(ply, number, caller)
	BuySent(ply, "rpdm_buysent", {caller})
	return ""
end

function dropWeapon(ply, args)
	local args = Purify(args)
	local wep
	if(args != nil && ply:GetWeapon(args):IsWeapon()) then
		wep = ply:GetWeapon(args) 
	else
		wep = ply:GetActiveWeapon()
	end
	if wep.ClassName && wep.ClassName != "gmod_tool" then
		ply:DropWeapon(wep)
		ply:SelectWeapon("weapon_physcannon")
	else
		ply:ChatPrint("This weapon cannot be dropped!")
	end
	return ""
end
AddChatCommand("/drop", dropWeapon)

function dropAllWeapons(ply)
	for k, wep in pairs(ply:GetWeapons()) do
		if wep.ClassName && wep.ClassName != "gmod_tool" then
			ply:DropWeapon(wep)
		end
	end
	ply:SelectWeapon("weapon_physcannon")
	return ""
end
AddChatCommand("/dropall", dropAllWeapons)

local function ChatUpgrade(ply)
	Upgrade(ply)
	return ""
end
AddChatCommand("/upgrade", ChatUpgrade)

function playerMobhit(ply, args)
	args = Purify(args)
	args = string.Explode(" ", args)  
		local v = FindPlayer(args[1])
		if ValidEntity(v) then
					if (tonumber(args[2])==nil) then
						Notify(ply, 4, 3, "Hit must be at least $100!")
					elseif(not ply:CanAfford(tonumber(args[2]))) then
						Notify(ply, 4, 3, "Cannot afford this")
					elseif (tonumber(args[2])<100) then
						Notify(ply, 4, 3, "Hit must be at least $100!")
					else
						ply:AddMoney(tonumber(args[2]) * -1)
						v:SetNWInt("hitlist", v:GetNWInt("hitlist")+math.Round(tonumber(args[2])))
						Notify(ply, 0, 3, "Hit set for $" .. math.Round(tonumber(args[2])))
						for a, b in pairs(player.GetAll()) do  
							if(b:Alive()) then
								b:PrintMessage(HUD_PRINTCENTER, v:Nick() .. " Has had a hit placed on them for $" .. math.Round(tonumber(args[2]))) 
							end
						end
					end  
		end 
	
	return ""
end
AddChatCommand("/placehit", playerMobhit)

function GetHelp(ply, args)
	datastream.StreamToClients(ply, "ShowTeamStatsStream", {StatsDB.Get(ply, "frags"),StatsDB.Get(ply, "time"),StatsDB.GetTop5("money"),StatsDB.GetTop5("frags"),StatsDB.GetTop5("time")})
	return ""
end
AddChatCommand("/help", GetHelp)

function WriteSign(ply, args)
	args = Purify(args)
	
	if(CurTime() - ply.LastLetterMade < 20) then
	
		Notify(ply, 4, 4, "Wait another " .. math.ceil(20 - (CurTime() - ply.LastLetterMade)) .. " seconds to make a sign")
		return ""
	
	end

	ply.LastLetterMade = CurTime()
	
	local ftext = string.gsub(args, "//", "\n")
	
	local tr = { }
	tr.start = ply:EyePos()
	tr.endpos = ply:EyePos() + 95 * ply:GetAimVector()
	tr.filter = ply
	local trace = util.TraceLine(tr)
	
	local letter = ents.Create("sign")
		letter:SetNWString("text", ftext)
		letter:SetPos(trace.HitPos)
		letter:SetNWEntity("owner",ply)
		letter:SetColor(tonumber(ply:GetInfo("rpdm_clcolor_r")),tonumber(ply:GetInfo("rpdm_clcolor_g")),tonumber(ply:GetInfo("rpdm_clcolor_b")),255)
	letter:Spawn()
	
	PrintMessageAll(2, ply:Nick() .. " created a sign.")
	ply:PrintMessage(2, "CREATED SIGN:\n" .. args)
	
	return ""

end
AddChatCommand("/buysign", WriteSign)
AddChatCommand("/sign", WriteSign)

function ChangeJob(ply, args)
    args = Purify(args)
    if(args == "") then return "" end
	
	NotifyAll(3, 4, ply:Nick() .. " has set job to " .. args .. "!")
	ply:SetNWString("job", args)
	
	return ""

end
AddChatCommand("/job", ChangeJob)